home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / Ant Movie Catalog 3.5.0.2 / amc_install.exe / {app} / Scripts / CineGR.ifs < prev    next >
Text File  |  2005-03-01  |  11KB  |  276 lines

  1. (***************************************************
  2.  
  3. Ant Movie Catalog importation script
  4. www.antp.be/software/moviecatalog/
  5.  
  6. [Infos]
  7. Authors=kolia (kolia@mailbox.gr)
  8. Title=Cine.GR
  9. Description=Import from www.cine.gr (appends info)
  10. Site=www.cine.gr
  11. Language=EL
  12. Version=1.0
  13. Requires=3.5.0
  14. Comments=Based on the script made for version 3.4.0 by kolia (kolia@mailbox.gr)
  15. License=This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  16. GetInfo=1
  17.  
  18. [Options]
  19. GetCinegrPicture=0|0|0=Do not import Picture|1=Import Picture
  20. GetSyntelestes=0|0|0=Do not import Syntelestes|1=Import Syntelestes
  21. GetCinegrComment=1|1|0=Don't import greek comment|1=You need to download another page (slower)
  22.  
  23. ***************************************************)
  24.  
  25. program CineGR;
  26.  
  27. const
  28.   ImportCINEGR = True;
  29.  
  30. var
  31.   MovieName: string;
  32.  
  33. // CINEGR Loads and analyses page from internet (list of movies or direct hit)
  34. procedure AnalyzePageCineGr(Address: string);
  35. var
  36.   Page: TStringList;
  37. begin
  38.   Page := TStringList.Create;
  39. //  Page.LoadFromFile('c:\testcine3.html');
  40.   Page.Text := GetPage(Address);
  41.   // check for error
  42.   if Pos('─σφ Γ±▌ΦτΩßφ ≤⌠∩Θ≈σ▀ß', Page.Text) > 0 then begin
  43.     if Input('Cine.GR Import', 'Enter the title of the movie:'+#13#10+'(if not found Press Cancel and No to continue)', MovieName) then
  44.       AnalyzePageCineGr('http://www.cine.gr/results.asp?term='+UrlEncode(MovieName)+'&type=film&image.x=16&image.y=16');
  45.   // movie list
  46.   end else if Pos('>Cine.gr - Quick Search - ┴≡∩⌠σδ▌≤∞ß⌠ß<', Page.Text) > 0 then begin
  47.     PickTreeClear;
  48.     PickTreeAdd('Search results from cine.gr', '');
  49.     AddMoviesTitlesCineGR(Page);
  50.     if PickTreeExec(Address) then AnalyzePageCineGr(Address);
  51.   // refine search
  52.   end else if Pos('Sorry, there is too many possible matches, please adjust your search.', Page.Text) > 0 then begin
  53.     ShowMessage('Sorry, there is too many possible matches, please adjust your search.');
  54.     if Input('All Movie Import', 'Enter the title of the movie:', MovieName) then
  55.       AnalyzePageCineGr('http://www.cine.gr/results.asp?term='+UrlEncode(MovieName)+'&type=film&image.x=16&image.y=16');
  56.   // direct hit
  57.   end else begin
  58.     AnalyzeMoviePageCineGr(Page);
  59.   end;
  60. end;
  61.  
  62. // Adds movie titles from search results to tree
  63. procedure AddMoviesTitlesCineGR(ResultsPage: TStringList);
  64. var
  65.   Page: string;
  66.   MovieTitle, MovieAddress: string;
  67. begin
  68.   Page := ResultsPage.Text;
  69.   // Every movie entry begins with string "film.asp?id="
  70.   while Pos('film.asp?id=', Page) > 0 do begin
  71.     CutBefore(Page, 'film.asp?id=');
  72. //    CutBefore(Page, 'href="http://www.cine.gr/film.asp?');
  73.     MovieAddress := 'http://www.cine.gr/film.asp?' + GetStringFromHTML(Page, 'film.asp', '?', '">');
  74.     MovieTitle := GetStringFromHTML(Page, 'film.asp', '">', '</');
  75.     MovieTitle := StringReplaceAll(MovieTitle, #13#10, ' ');//replace returns with spaces
  76.     MovieTitle := StringReplaceAll(MovieTitle, '  ', ' ');//replace multiple spaces
  77.     CutAfter(Page, '</');
  78.     // add movie to list
  79. //    ShowMessage('MovieTitle= '+MovieTitle+' MovieAddress= '+MovieAddress);
  80.     PickTreeAdd(MovieTitle, MovieAddress);
  81.   end;
  82. end;
  83.  
  84. // simple string procedures
  85. function StringReplaceAll(S, Old, New: string): string;
  86. begin
  87.   while Pos(Old, S) > 0 do
  88.     S := StringReplace(S, Old, New);
  89.   Result := S;
  90. end;
  91.  
  92. procedure CutAfter(var Str: string; Pattern: string);
  93. begin
  94.   Str := Copy(str, Pos(Pattern, Str) + Length(Pattern), Length(Str));
  95. end;
  96.  
  97. procedure CutBefore(var Str: string; Pattern: string);
  98. begin
  99.   Str := Copy(Str, Pos(Pattern, Str), Length(Str));
  100. end;
  101.  
  102. // Extracts single movie detail (like director, genre) from page
  103. function GetStringFromHTML(Page, StartTag, CutTag, EndTag: string): string;
  104. begin
  105.   Result := '';
  106.   // recognition tag - if present, extract detail from page, otherwise assume detail is not present
  107.   if Pos(StartTag, Page) > 0 then begin
  108.     CutBefore(Page, StartTag);
  109.     // optional cut tag helps finding right string in html page
  110.     if Length(CutTag) > 0 then
  111.       CutAfter(Page, CutTag);
  112.     // movie detail copied with html tags up to end string
  113.     Result := Copy(Page, 0, Pos(EndTag, Page) - 1);
  114.     // remove html tags and decode html string
  115.     HTMLRemoveTags(Result);
  116.     HTMLDecode(Result);
  117. //  ShowMessage('DEBUG: GetStringFromHTML - StartTag "'+StartTag+'", CutTag "'+CutTag+'", EndTag "'+EndTag+'", Result "'+Result+'" ___ '+Page);
  118.   end;
  119. end;
  120.  
  121. // Extracts movie details from page
  122. procedure AnalyzeMoviePageCineGr(MoviePage: TStringList);
  123. var
  124.   Page, Page1, Value, Value2, FullValue, Perigrafh: string;
  125. begin
  126.   Page := MoviePage.Text;
  127.   
  128. {  //Cine.gr URL Import
  129.     if Length(MovieAddress) > 0 then
  130.     begin
  131.       SetField(fieldComments, GetField(fieldComments)+'Cine.gr URL:('+MovieAddress+')');
  132.     end;
  133. }
  134.   //Cinegr Picture
  135.     if GetOption('GetCinegrPicture') = 1 then
  136.     begin
  137.       Value := GetStringFromHTML(Page, 'FilmImages', 'FilmImages/', '"');
  138.       Value := 'http://www.cine.gr/FilmImages/'+Value;
  139.       if Length(Value) > 0 then
  140.       begin
  141.         GetPicture(Value);
  142.       end;
  143.     end;
  144.  
  145.   //╠σ⌠ß÷±ß≤∞▌φ∩≥ ╘▀⌠δ∩≥
  146.     Value := GetStringFromHTML(Page, '- ╠σ⌠ß÷±ß≤∞▌φ∩≥ ╘▀⌠δ∩≥:', '"><b>', '</b>');
  147.     if Length(Value) > 0 then
  148.     begin
  149.       SetField(fieldTranslatedTitle, GetField(fieldTranslatedTitle)+' ['+Value+']');
  150.     end;
  151.  
  152.   //╒≡ⁿ⌠Θ⌠δ∩≥:
  153.     Value := GetStringFromHTML(Page, '╒≡ⁿ⌠Θ⌠δ∩≥:', '">', '</font>');
  154.     if Length(Value) > 0 then
  155.     begin
  156.       Value := StringReplace(Value, #13#10, ' ');//replace returns with spaces
  157.       SetField(fieldDescription, '╒≡ⁿ⌠Θ⌠δ∩≥: '+Value+#13#10+#13#10+GetField(fieldDescription));
  158.     end;
  159.  
  160.   //╨±σ∞Θ▌±ß ≤⌠τφ ┼δδ▄Σß
  161.     Value := GetStringFromHTML(Page, '╨±σ∞Θ▌±ß ≤⌠τφ ┼δδ▄Σß:', '">', '</a>');
  162.     if Length(Value) > 0 then
  163.     begin
  164.       SetField(fieldDescription, '╨±σ∞Θ▌±ß ≤⌠τφ ┼δδ▄Σß: '+Value+#13#10+#13#10+GetField(fieldDescription));
  165.     end;
  166.  
  167.   //╙⌡φ⌠σδσ≤⌠▌≥
  168.   if GetOption('GetSyntelestes') = 1 then
  169.   begin
  170.   if Pos('">╙⌡φ⌠σδσ≤⌠▌≥ :', Page) > 0 then begin
  171.     Page1 := Copy(Page, Pos('╙⌡φ⌠σδσ≤⌠▌≥ :', Page), Length(Page));//gia na mhn alazei to page
  172.     //CutBefore(Page, '╙⌡φ⌠σδσ≤⌠▌≥ :');
  173.     //CutAfter(Page, '╨σ±Θ≤≤ⁿ⌠σ±∩Θ ╙⌡φ⌠σδσ≤⌠▌≥...');
  174.     while Pos('people.asp?name=', Page1) > 0 do begin
  175.       CutBefore(Page1, 'people.asp?name='); //Recognition Tag
  176.       //CutBefore(Page1, '">');//Start Tag
  177.       Page1 := Copy(Page1, Pos('">', Page1) + 2, Length(Page1));//copy after the string
  178.       Value := Copy(Page1, 0, Pos('</', Page1) - 1);
  179.       Page1 := Copy(Page1, Pos('>....', Page1) + 5, Length(Page1));//copy after the string
  180.       Perigrafh := Copy(Page1, 0, Pos('</', Page1) - 1);
  181.       case Perigrafh of
  182.         '╟Φ∩≡∩Θⁿ≥':
  183.           begin
  184.             Page1 := Copy(Page1, Pos('>....', Page1) + 5, Length(Page1));//copy after the string
  185.             Value2 := Copy(Page1, 0, Pos('</', Page1) - 1);
  186.             if FullValue <> '' then FullValue := FullValue + #13#10;
  187.             FullValue := FullValue+Value+' ... '+Value2;
  188.             // remove html tags and decode html string
  189.             HTMLRemoveTags(FullValue);
  190.             HTMLDecode(FullValue);
  191.             SetField(fieldActors, FullValue);
  192.           end;
  193.         '╙Ωτφ∩Φσ⌠τ≥':
  194.           begin
  195.             SetField(fieldDirector, Value);
  196.           end;
  197.         '╙σφß±Θ∩π±▄÷∩≥':
  198.           begin
  199.             SetField(fieldProducer, Value+' (╙σφß±Θ∩π±▄÷∩≥)');
  200.           end;
  201.       end;
  202.     end;
  203.     end;
  204.   end;
  205.  
  206.   //╒≡ⁿΦσ≤τ & ╨ß±ßδσΘ≡ⁿ∞σφß (╘σδσ⌡⌠ß▀∩ πΘß⌠▀ ßδδ▄µσΘ ⌠∩ Page)
  207.     if GetOption('GetCinegrComment') = 1 then
  208.     begin
  209.       Value := GetStringFromHTML(Page, '╒≡ⁿΦσ≤τ & ╨ß±ßδσΘ≡ⁿ∞σφß', '<a href="', '">');
  210.       if Length(Value) > 0 then
  211.       begin
  212.         Value := Copy(Value, 0, Length(Value) - 1) + '2';//always go to page=2
  213.         Value := StringReplaceAll(Value, '&', '&');
  214.         Value := 'http://www.cine.gr/'+Value;
  215.         Page := GetPage(Value);
  216.         if Pos('╨δ∩Ω▐:', Page) > 0 then
  217.         begin
  218.           CutBefore(Page, '╨δ∩Ω▐:');
  219.           CutBefore(Page, '<font');
  220. //          CutBefore(Page, '<BR>'); //den htan se ola etsi :(
  221. //          CutBefore(Page, '<br>');
  222.           // movie detail copied with html tags up to end string
  223.           Value := Copy(Page, 0, Pos('</font', Page) - 1);//alla3a to string se '</font' apo '</'
  224. //         Value := GetStringFromHTML(Page, '╨δ∩Ω▐:', '<BR>', '</');
  225.         Value := StringReplaceAll(Value, #13#10, ' ');
  226.         Value := StringReplaceAll(Value, '…', '...');
  227.         Value := StringReplaceAll(Value, '<br>', #13#10);
  228.         Value := StringReplaceAll(Value, '<BR>', #13#10);
  229.         Value := StringReplaceAll(Value, '</p>', #13#10 #13#10);
  230.         Value := StringReplaceAll(Value, '</P>', #13#10 #13#10);
  231.         Value := StringReplaceAll(Value, '  ', ' ');
  232.         Value := StringReplaceAll(Value, #13#10+' ', #13#10);
  233.         Value := StringReplaceAll(Value, '╢', 'ó');
  234.         Value := StringReplaceAll(Value, '–', '-');
  235.         Value := StringReplaceAll(Value, '’', #39);
  236.         Value := StringReplaceAll(Value, '“', #34);
  237.         Value := StringReplaceAll(Value, '”', #34);
  238.         // remove html tags and decode html string
  239.         HTMLRemoveTags(Value);
  240.         HTMLDecode(Value);
  241.         if Length(Value) > 0 then
  242.         begin
  243.           SetField(fieldDescription, '╨δ∩Ω▐:'+#13#10+Value+#13#10+#13#10+GetField(fieldDescription));
  244.         end;
  245.         end;
  246.       end;
  247.     end;
  248.  
  249. end;
  250.  
  251. begin
  252.   if CheckVersion(3,5,0) then
  253.   begin
  254.       MovieName := GetField(fieldTranslatedTitle);
  255.     if (MovieName = '') then
  256.       MovieName := GetField(fieldOriginalTitle);
  257.     if MovieName = '' then
  258.       if not Input('IMDb Import', 'Enter the title of the movie:', MovieName) then
  259.         Exit;
  260.     if ImportCINEGR then
  261.      begin
  262.         if Pos('[', MovieName) > 0 then
  263.         begin
  264.           MovieName := Copy(MovieName, 0, Pos('[', MovieName) - 2);
  265.           SetField(fieldTranslatedTitle,MovieName);//8a mpoyn pali apo to cine gr
  266.         end;
  267.         if Pos('(', MovieName) > 0 then
  268.           MovieName := Copy(MovieName, 0, Pos('(', MovieName) - 2);
  269.         AnalyzePageCineGr('http://www.cine.gr/results.asp?term='+UrlEncode(MovieName)+'&type=film&image.x=16&image.y=16');
  270.      end;
  271. //      DisplayResults;
  272.   end
  273.   else
  274.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.5.0)');
  275. end.
  276.